import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { SRaceRooms } from "../../../../Message/Public/SRaceRooms";
import { SRaceRoomInfo } from "../../../../Message/Public/SRaceRoomInfo";
import { RaceCopyRoomItem } from "./RaceCopyRoomItem";
import { SRaceRoom } from "../../../../Message/Public/SRaceRoom";
import { SRaceRoomPlayerNum } from "../../../../Message/Public/SRaceRoomPlayerNum";
import { ObjCreate } from "../common/ObjCreate";
import { SecTimerView } from "../common/SecTimerView";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { CopyConfig } from "../../resource/CopyConfig";
type int = number;
//class RaceCopyRoomChooseWin
    
    export  class RaceCopyRoomChooseWin extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(679, 424);
            titleHeight = 26;
            title = Language.getString(80149);
            this.initView();
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.pageChangeHandler);
            return;
        }

        public updateWiew(arg1: SRaceRooms): void
        {
            if (arg1 == null) 
            {
                return;
            }
            if (arg1.reset) 
            {
                this.clearAndResetRooms(arg1.rooms);
            }
            else 
            {
                this.resetRooms(arg1.rooms);
            }
            return;
        }

        public updateRoomInfo(arg1: SRaceRoomInfo): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=0;
            while (loc1 < this._roomsItems.length) 
            {
                loc2 = this._roomsItems[loc1] as RaceCopyRoomItem;
                if (loc2.data != null) 
                {
                    if (loc2.data.roomId == arg1.roomId) 
                    {
                        (loc3 = new SRaceRoom()).isStart = arg1.isStart;
                        loc3.playerNum = arg1.playerNum;
                        loc3.maxPlayerNum = arg1.maxPlayerNum;
                        loc3.roomId = arg1.roomId;
                        loc2.updateView(loc3);
                        break;
                    }
                }
                ++loc1;
            }
            return;
        }

        public updateRoomPlayerNum(arg1: SRaceRoomPlayerNum): void
        {
            return;
        }

        public clearAndResetRooms(arg1: Array<any>): void
        {
            var loc2=null;
            this._data = arg1;
            var loc1=arg1.length;
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.maxPage = Math.ceil(arg1.length / (this.rowNum * this.lineNum));
            this.pageChangeHandler(null);
            return;
        }

        public resetRooms(arg1: Array<any>): void
        {
            return;
        }

        public updateLeftTime(arg1: int): void
        {
            this._leftTimer.setLeftTime(arg1);
            this._leftTimer.visible = true;
            this._started.visible = false;
            this._leftTimer.timeOutHandler = this.timeStartHandler;
            return;
        }

        public setStarted(): void
        {
            this._leftTimer.stop();
            this._leftTimer.visible = false;
            this._started.visible = true;
            return;
        }

        /* internal  */timeStartHandler(): void
        {
            this._leftTimer.visible = false;
            this._started.visible = true;
            return;
        }

        /* internal  */pageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=null;
            var loc1=(this._pageSelecter.currentPage - 1) * this.PageNum;
            var loc2=loc1 + this.PageNum;
            var loc3=loc1;
            while (loc3 < loc2) 
            {
                loc4 = this._roomsItems[loc3 - loc1] as RaceCopyRoomItem;
                if (loc3 > 15) 
                {
                    loc4.visible = false;
                }
                loc4.visible = true;
                loc5 = null;
                loc6 = 0;
                while (loc6 < this._data.length) 
                {
                    if (!((loc7 = this._data[loc6] as SRaceRoom) == null) && loc7.roomId == loc3 + 1) 
                    {
                        loc5 = loc7;
                        break;
                    }
                    ++loc6;
                }
                if (loc5 != null) 
                {
                    loc4.updateView(loc5);
                }
                else 
                {
                    loc4.setNotOpened();
                }
                ++loc3;
            }
            return;
        }

        /* internal  */initView(): void
        {
            var loc5=0;
            var loc6=null;
            ObjCreate.createBg(18, 38, 643, 337, this);
            this._leftTimer = new SecTimerView();
            ObjCreate.setObjAttri(this._leftTimer, 440, 385, 300, 30, this);
            var loc1=new GTextFormat(FontUtil.songtiName, 18, 16580352);
            loc1.bold = true;
            this._leftTimer.defaultTextFormat = loc1;
            this._leftTimer.filters = [FilterConst.glowFilter];
            this._leftTimer.setParse(Language.getString(44493));
            this._leftTimer.mouseEnabled = false;
            this._leftTimer.mouseWheelEnabled = false;
            this._started = ObjCreate.createGTextField("", 440, 385, 300, 30, this);
            this._started.defaultTextFormat = loc1;
            this._started.filters = [FilterConst.glowFilter];
            this._started.htmlText = Language.getString(80152);
            this._started.mouseEnabled = false;
            this._started.mouseWheelEnabled = false;
            this._started.visible = false;
            this._roomsItems = [];
            var loc2=0;
            while (loc2 < this.rowNum) 
            {
                loc5 = 0;
                while (loc5 < this.lineNum) 
                {
                    (loc6 = new RaceCopyRoomItem()).x = 30 + loc5 * 125;
                    loc6.y = 60 + loc2 * 126;
                    this.addChild(loc6);
                    this._roomsItems.push(loc6);
                    loc6.setNotOpened();
                    ++loc5;
                }
                ++loc2;
            }
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            ObjCreate.setObjAttri(this._pageSelecter, 278, 334, -1, -1, this);
            var loc3=ObjCreate.createGTextField("", 18, 380, 440, 20, this);
            loc3.textColor = GlobalStyle.color5Uint;
            loc3.htmlText = Language.getString(80154);
            loc3 = ObjCreate.createGTextField("", 18, 397, 440, 20, this);
            loc3.textColor = GlobalStyle.color5Uint;
            var loc4=CopyConfig.instance.getInfoByCode(152);
            loc3.htmlText = Language.getStringByParam(80155, loc4.enterMinLevel.toString());
            return;
        }

        /* internal */ /* const */rowNum: int=2;

        /* internal */ /* const */lineNum: int=5;

        /* internal */ /* const */PageNum: int=10;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_leftTimer: SecTimerView;

        /* internal */ /* var */_started: Object /* flash.text.TextField */;

        /* internal */ /* var */_roomsItems: Array<any>;

        /* internal */ /* var */_data: Array<any>;
    }
